<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>作用域插槽的使用</title>
</head>
<body>
  <div id="app">
    <cpn></cpn>

    <cpn>
      <!-- 2.6.0已废弃的语法 -->
      <!-- <template slot-scope="slot"> -->
      <!-- 新语法：slot-scope -> v-slot -->
      <template v-slot="slot"> <!-- 不可以写成#slot，注意默认插槽的缩写语法不能和具名插槽混用 -->
        <!-- v-slot后的名称是自定义的，与模板内对应就可以，比如与span标签内的slot对应 -->
        <span> {{slot.data.join(' - ')}} </span>
      </template>
    </cpn>

    <cpn v-slot="slot"> <!-- template也可省去 -->
      <span> {{slot.data.join(' * ')}} </span>
    </cpn>

  </div>

  <template id="cpn">
    <div>
      <slot :data="pLanguage">
        <ul>
          <li v-for="item of pLanguage">{{item}}</li>
        </ul>
      </slot>
    </div>
  </template>

  <script src="../js/vue.js"></script>
  <script>

    const app = new Vue({
      el: '#app',
      data: {
        message: '你好啊',
      },
      components: {
        cpn: {
          template: '#cpn',
          data() {
            return {
              pLanguage: ['JavaScript','C++','Java','C#','Python','Go','Swift']
            }
          }
        }
      }
    })
    
  </script>
</body>
</html>